
#include<iostream>
#include<string>
using namespace std;

/* CPU */
class CPU
{
public:
	virtual void calculate() = 0;
public:
	string source;
};

/* IntelCPU */
class IntelCPU :public CPU
{
public:
	virtual void calculate() {
		if (source.empty()) {
			source = "#未指定#";
		}
		cout <<this->source<< "Intel的CPU开始计算了！" << endl;
	}
};
/* LenovoCPU */
class LenovoCPU :public CPU
{
public:
	virtual void calculate()
	{
		if (source.empty()) {
			source = "#未指定#";
		}
		cout << this->source << "Lenovo的CPU开始计算了！" << endl;
	}
};
/* VideoCard */
class VideoCard
{
public:
	virtual void display() = 0;
};
/* LenovoVideoCard */
class LenovoVideoCard :public VideoCard
{
public:
	virtual void display()
	{
		cout << "Lenovo的显卡开始显示了！" << endl;
	}
};
/* IntelVideoCard */
class IntelVideoCard :public VideoCard
{
public:
	virtual void display()
	{
		cout << "Intel的显卡开始显示了！" << endl;
	}
};
/* Memory */
class Memory
{
public:
	virtual void storage() = 0;
};
/* IntelMemory */
class IntelMemory :public Memory
{
public:
	virtual void storage()
	{
		cout << "Intel的内存条开始存储了！" << endl;
	}
};

/* LenovoMemory */
class LenovoMemory :public Memory
{
public:
	virtual void storage()
	{
		cout << "Lenovo的内存条开始存储了！" << endl;
	}
};

/* Computer */
class Computer
{
private:
	CPU* cpu;
	VideoCard* videoCard;
	Memory* memory;
	LenovoMemory len;
public:
	Computer(CPU* cpu, VideoCard* videoCard, Memory* memory) {
		cout << "开始构建一台 电脑 " << endl;
		this->cpu = cpu;
		this->videoCard = videoCard;
		this->memory = memory;
	}

	~Computer() {
		cout << "开始拆除（析构）一台 电脑 " << endl;
		if (this->cpu != NULL) {
			delete this->cpu;
			cpu = NULL;
		}
		if (this->videoCard != NULL) {
			delete this->videoCard;
			videoCard = NULL;
		}
		if (this->memory != NULL) {
			delete this->memory;
			memory = NULL;
		}
	}

	void work() {
		this->cpu->calculate();
		this->videoCard->display();
		this->memory->storage();
	}


};

void test01()
{
	//第一台电脑零件
	CPU* intelCpu = new IntelCPU;
	intelCpu->source = "#Intel#";
	VideoCard* intelCard = new IntelVideoCard;
	Memory* intelMem = new IntelMemory;

	cout << "第一台电脑开始工作：" << endl;
	//创建第一台电脑
	Computer* computer1 = new Computer(intelCpu, intelCard, intelMem);
	computer1->work();
	delete computer1;

	cout << "-----------------------" << endl;
	cout << "第二台电脑开始工作：" << endl;
	//第二台电脑组装
	Computer* computer2 = new Computer(new LenovoCPU, new LenovoVideoCard, new LenovoMemory);
	computer2->work();
	delete computer2;

	cout << "-----------------------" << endl;
	cout << "第三台电脑开始工作：" << endl;
	//第三台电脑组装
	Computer* computer3 = new Computer(new LenovoCPU, new IntelVideoCard, new LenovoMemory);;
	computer3->work();
	delete computer3;

}

int main() {
	test01();
	system("pause");
	return 0;
}